from odoo import fields, models, api


class StockMove(models.Model):
    _inherit = 'stock.move'

    # s_reconciled = fields.Boolean('Reconciled', default=False, copy=False, readonly=True)
    s_invoice_lines = fields.One2many('account.move.line', 's_stock_move_id')
    s_qty_invoiced = fields.Float(compute='_compute_qty_invoiced', string="Billed Qty", digits='Product Unit of Measure', store=True)

    @api.depends('s_invoice_lines.move_id.state', 's_invoice_lines.quantity', 'product_uom_qty', 'picking_id.state')
    def _compute_qty_invoiced(self):
        for move in self:
            qty = 0.0
            for inv_line in move.s_invoice_lines:
                if inv_line.move_id.state not in ['cancel'] or inv_line.move_id.payment_state == 'invoicing_legacy':
                    if inv_line.move_id.move_type == 'in_invoice':
                        qty += inv_line.product_uom_id._compute_quantity(abs(inv_line.quantity), move.product_uom)
                    elif inv_line.move_id.move_type == 'in_refund':
                        qty -= inv_line.product_uom_id._compute_quantity(abs(inv_line.quantity), move.product_uom)
            move.s_qty_invoiced = qty
